//easyui-combotree的扩展
(function($) {
	//组织机构combotree 过滤查询
	function queryComboTree(q, comboid) {
		var datalist = [];//用平面的combobox来展示过滤的结果
		var childrenlist = [];
		var combotreeid = "#" + comboid;
		var roots = $(combotreeid).combotree('tree').tree('getRoots');//得到根节点数组
		var children;
		var entertext = $(combotreeid).combotree('getText');
		$(combotreeid).combotree('setText', q);
		if (entertext == null || entertext == "") {//如果文本框的值为空，或者将文本框的值删除了，重新reload数据
		    $(combotreeid).combotree('reload');
		    $(combotreeid).combotree('clear');
		    $(combotreeid).combotree('setText', q);
		    return;
		}
		//循环数组，找到与输入值相似的，加到前面定义的数组中，
		for (i = 0; i < roots.length; i++) {
		    if (q == roots[i].text) {
			$(combotreeid).combotree('tree')
				.tree('select', roots[i].target);
			    return;
		    } else {
			if (roots[i].text.indexOf(q) >= 0 && roots[i].text != "") {
			    var org = {
			        "id" : roots[i].id,
				"text" : roots[i].text
				    };
			    datalist.push(org);
			}
		    }
	             //找子节点（递归）
		    //childrensTree(combotreeid, roots[i].target, datalist, q);
	        }
			//如果找到相似的结果，则加载过滤的结果
			if (datalist.length > 0) {
				$(combotreeid).combotree('loadData', datalist);
				$(combotreeid).combotree('setText', q);
				datalist = [];//这里重新赋值是避免再次过滤时，会有重复的记录
				return;
			} else {
			   //$(combotreeid).combotree('reload');
				//$(combotreeid).combotree('clear');
				$(combotreeid).combotree('setText', q);
				return;
			}
		}

		
})(jQuery);